﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities.QuickSql;
using MySql.Data;

namespace Deviseur_Cs2i_Car
{
    public partial class AdminVoiCouleurCarross: Form
    {
        public AdminVoiCouleurCarross()
        {
            InitializeComponent();

            Thread VoiCouleurCarrossThread = new Thread(new ThreadStart(getAllVoiCouleurCarross_Thread));
            VoiCouleurCarrossThread.Start();
        }

        private void getAllVoiCouleurCarross_Thread()
        {
            Invoke(new MethodInvoker(getAllVoiCouleurCarross));
        }

        private void getAllVoiCouleurCarross()
        {
            Table VoiCouleurCarross = Program.Db.QueryTable("SELECT V.NomVoi, C.LibelleCouleurCaross,C.MetalCouleurCaross,C.PrixCouleurCaross,V.NumVoi,C.NumCouleurCaross FROM Voi_Couleur VC INNER JOIN VOITURE V ON V.NumVoi=VC.NumVoi INNER JOIN COULEURCAROSS C ON C.NumCouleurCaross= VC.NumCouleurCaross ");

            this.dataVoiCouleurCarross.Rows.Clear();

            foreach (Record r in VoiCouleurCarross)
                this.dataVoiCouleurCarross.Rows.Add(r.Values[0], r.Values[1], r.Values[2], r.Values[3], r.Values[4], r.Values[5]);
        }

        private void AdminVoiCouleurCarross_Activated(object sender, EventArgs e)
        {
            Thread VoiCouleurCarossThread = new Thread(new ThreadStart(getAllVoiCouleurCarross_Thread));
            VoiCouleurCarossThread.Start();
        }

        private void buttonDel_Click(object sender, EventArgs e)
        {
            VoiCouleurCarross delVoiCouleurCaross = new VoiCouleurCarross();
            delVoiCouleurCaross.delete_VoiCouleurCarross(Convert.ToInt32(this.dataVoiCouleurCarross.SelectedRows[0].Cells[4].Value.ToString()), Convert.ToDouble(this.dataVoiCouleurCarross.SelectedRows[0].Cells[5].Value.ToString()));
            Thread VoiMotorThread = new Thread(new ThreadStart(getAllVoiCouleurCarross_Thread));
            VoiMotorThread.Start();
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            AddVoiCouleurCarross FenAddcouleurvoi= new AddVoiCouleurCarross();
            FenAddcouleurvoi.ShowDialog();
        }


   /*     

        private void buttonModifVoiMotor_Click(object sender, EventArgs e)
        {
            AddVoiMotor FenAddVoiMotor = new AddVoiMotor(Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[5].Value.ToString()), Convert.ToDouble(this.dataGridView1.SelectedRows[0].Cells[6].Value.ToString()));
            FenAddVoiMotor.ShowDialog();
        }*/
    }
}
